<?php
require_once 'BaseController.php';

/**
 * 【SP版】店舗検索(地域・沿線・駅選択) コントローラ
 */
class Mobileapi_ShopsearchController extends Mobileapi_BaseController
{

    /**
     * メインアクション
     */
    public function indexAction()
    {
        $params = $this->getParameters();

        $cat = $params['Category'];
        if (empty($cat)) $cat = 'index';

        $area = $params['Area'];

        if ($cat == 'index')
        {
            $this->makeTemplateParams1($area);
        }
        else if ($cat == 'line')
        {
            $rail = $params['RailCd'];
            if ($rail == '') $cat = 'route';
            $this->makeTemplateParams2($area, $rail);
        }

        $this->displayBody2($cat);
    }

    private function makeTemplateParams1($area)
    {
        $model = new Shop_Model_SelectCity();

        $params = array();
        $prefCd = $this->getPrefCode($area);
        $this->getPrefData($prefCd);

        $params['PrefCd'][] = $prefCd;
        $r1 = $model->getList($params);
        $data = $model->convertData($r1, $params);

        $this->_data['Mapping'] = $data;
        $this->_data['Mapping_area'] = $area;
        $this->_data['Mapping_area_code'] = $this->getPrefCode($area);
    }

    private function makeTemplateParams2($area, $rail)
    {
        $model = new Shop_Model_SelectRail();
        $params = array();
        $prefCd = $this->getPrefCode($area);
        $this->getPrefData($prefCd);

        $params['PrefCd'][] = $prefCd;
        if (!empty($rail)) $params['RailCd'][] = $rail;

        $r1 = $model->getList($params);
        $data = $model->convertData($r1, $params);
        $this->_data['Mapping'] = $data;
        $this->_data['Mapping_area'] = $area;
        $this->_data['Mapping_area_code'] = $this->getPrefCode($area);
    }

    public function getPrefData($code)
    {
        $model = new Search_Model_Selareasearch();
        $prefInfo = $model->getSimpleArea($code);
        $this->_data['PrefInfo'] = $prefInfo;
        $this->_data['PrefNameJP'] = $this->getPrefNameJP($code);
        $this->_data['PrefNameJPWithoutPostfix'] = $this->getPrefNameWithoutPostfix($this->_data['PrefNameJP']);
        $this->_data['RandomPrefs'] = $this->getRandomPrefs(5);
    }

}
?>
